﻿$(document).ready(function () {
    //Run on Chorme , Firefox , IE
    //Diable right menu
//    $("#email_confirm").bind("contextmenu", function (e) {
//        return false;
//    });

//    //Disable Ctr + c,v,x
//    $('#email_confirm').keydown(function (event) {
//        var forbiddenKeys = new Array('c', 'x', 'v');
//        var keyCode = (event.keyCode) ? event.keyCode : event.which;
//        var isCtrl;
//        isCtrl = event.ctrlKey
//        if (isCtrl) {
//            for (i = 0; i < forbiddenKeys.length; i++) {
//                if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
//                    return false;
//                }
//            }
//        }
//        return true;
//    });



    //Disable f5 , Ctr+R in Chrome
    function checkKeyCode(evt) {

        var evt = (evt) ? evt : ((event) ? event : null);
        var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (event.keyCode == 116) {
            evt.keyCode = 0;
            return false
        }
        if (event.keyCode == 82) {
            evt.keyCode = 0;
            return false
        }
    }
    document.onkeydown = checkKeyCode;

    //Disable f5 , Ctr+R in IE
    document.onkeydown = function () {
        if (event.keyCode == 116) { event.keyCode = 0; event.cancelBubble = true; return false; }
    }

    //////////////////////////////////////////
    //Disable f5 on Firefox
    function disableKey(event) {
        if (!event) event = window.event;
        if (!event) return;

        var keyCode = event.keyCode ? event.keyCode : event.charCode;

        //window.status = keyCode;
        //alert(keyCode);

        // keyCode for F% on Opera is 57349 ?!

        if (keyCode == 116) {
            window.status = "F5 key detected! Attempting to disabling default response.";
            window.setTimeout("window.status='';", 2000);

            // Standard DOM (Mozilla):
            if (event.preventDefault) event.preventDefault();

            //IE (exclude Opera with !event.preventDefault):
            if (document.all && window.event && !event.preventDefault) {
                event.cancelBubble = true;
                event.returnValue = false;
                event.keyCode = 0;
            }

            return false;
        }

        if (keyCode == 82) {
            window.status = "F5 key detected! Attempting to disabling default response.";
            window.setTimeout("window.status='';", 2000);

            // Standard DOM (Mozilla):
            if (event.preventDefault) event.preventDefault();

            //IE (exclude Opera with !event.preventDefault):
            if (document.all && window.event && !event.preventDefault) {
                event.cancelBubble = true;
                event.returnValue = false;
                event.keyCode = 0;
            }

            return false;
        }
    }
    document.onkeydown = disableKey;


    //function setEventListener(eventListener) {
    //	  if (document.addEventListener) document.addEventListener('keypress', eventListener, true);
    //	  else if (document.attachEvent) document.attachEvent('onkeydown', eventListener);
    //	  else document.onkeydown = eventListener;
    //	  
    //	  if (!document.getElementById) return;
    //	  var el = document.getElementById("Msg");
    //	  if (el) el.innerHTML = "Event handler added.";
    //	}
    //	
    //	function unsetEventListener(eventListener) {
    //	  if (document.removeEventListener) document.removeEventListener('keypress', eventListener, true);
    //	  else if (document.detachEvent) document.detachEvent('onkeydown', eventListener);
    //	  else document.onkeydown = null;
    //	  
    //	  if (!document.getElementById) return;
    //	  var el = document.getElementById("Msg");
    //	  if (el) el.innerHTML = "Event handler removed.";
    //	}
    /////////////////////////////////////////////////////		




});



